#include <rtthread.h>
#include <stdio.h>

#include <spl0601.h>

using namespace NXMFC;

#define SPL_I2C ":dev/i2c1"

static int spl(int argc, char **argv)
{
    spl0601 s;
    int cnt = 50;
    char *devnm = SPL_I2C;

    if (argc == 2)
        devnm = argv[1];

    if (!s.open(devnm))
    {
        printf("open fail\r\n");
        return -1;
    }

    if (!s.init())
    {
        s.close();
        printf("init fail\r\n");
        return -1;
    }

    while (cnt-- > 0)
    {
        int p = 0;
        float fp;

        if (!s.rawPressure(p))
        {
            printf("read fail\r\n");
            break;
        }

        fp = s.pressure();

        printf("R[%d], P[%.2f], A[%.2f], T[%.2f]\r\n", p, fp, s.pressureToAltitude(fp), s.temperature());
        rt_thread_mdelay(1000);
    }

    return 0;
}
MSH_CMD_EXPORT(spl, test spl0601);
